const app = new Vue({
    el: '#app',
    data: {
        kucundata: [],
        kucun_total: 100,
        currentpage: 1,
        pagesize: 10,
        // baseURL: "http://10.246.29.52:1111/",
        baseURL: "http://10.243.49.86:8001/",
        pagekucundata: [],
        inputstr:'',

    },
    mounted() {
        //自动加载数据
        this.getkucun();
    },
    methods: {
        getkucun: function () {
            let that = this
            axios.get(that.baseURL + '/api_get/get_kucun').then(
                function (res) {
                    if (res.data.code === 1) {
                        //把数据给kucundata
                        that.kucundata = res.data.data;
                        //获取记录的总行数
                        that.kucun_total = res.data.data.length;
                        that.getpagekucun()
                        that.$message({
                            message: '数据加载成功',
                            type: 'success'
                        })
                    } else {
                        that.$message.error(res.data.msg)
                    }
                }
            ).catch(
                function (err) {
                    console.log(err)
                }
            )
        },
        getpagekucun() {
            //清空pagekucundata
            this.pagekucundata = []
            for(let i = (this.currentpage-1)*this.pagesize;i<this.kucun_total;i++){
                //遍历数据添加到pagekucundata
                this.pagekucundata.push(this.kucundata[i]);
                if(this.pagekucundata.length === this.pagesize) break;
            }
        },
        //分页时修改每页的行数
        handleSizeChange(size){
            //修改当前每页的行数
            this.pagesize = size;
            //数据重新分页
            this.getpagekucun();
        },
        //调整当前的页码
        handleCurrentChange(pageNumber){
            this.currentpage = pageNumber
            this.getpagekucun();
        }
    },
})